package com.lsy.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.lsy.entity.Admin;

public class BackValidateInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		Admin admin = (Admin) request.getSession().getAttribute("admin");
		String login_url = request.getContextPath() + "/back/login";
		String login = request.getRequestURI();
		if (admin == null) {
			if(login_url.equals(login)){
				return true;
			}
			response.sendRedirect(request.getContextPath() + "/back/login");
			return false;
		} else {
			return true;
		}
	}

}
